package com.tinyseed.emcp.api.basicdata.repository;

import com.tinyseed.emcp.api.basicdata.domain.Workshop;
import com.tinyseed.emcp.api.dashboard.query.TreeQuickQuery;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

public interface WorkshopRepository extends JpaRepository<Workshop, Long> {

    List<Workshop> findAllByEnterpriseId(Long enterpriseId);

    @Transactional
    void deleteByEnterpriseId(Long id);

    @Query(value = "select id,shop_name,enterprise_id from tb_workshop", nativeQuery = true)
    List<Map<String, Object>> findWorks();

    @Query(value = "select new  com.tinyseed.emcp.api.dashboard.query.TreeQuickQuery(w.id,w.shopName,w.enterpriseId) from Workshop w")
    List<TreeQuickQuery> queryWorkshopTree();

}
